package merge

import (
	"game/game-design/export"
	"game/game-design/gen"
	"game/game-design/loader"
	"strings"
)

type CatalogArgs struct {
	TemplateFile string
	SourceHome   string
	Args         map[string]string
	DesignDefine *loader.DesignDefine
	Reader       export.IDesignIO
}

func NewCatalogArgs(args []string) *CatalogArgs {
	var catalogArgs CatalogArgs
	catalogArgs.Args = make(map[string]string)
	for _, arg := range args {
		parts := strings.Split(arg, " ")
		if strings.HasPrefix(arg, "-template") {
			catalogArgs.TemplateFile = parts[1]

		} else if strings.HasPrefix(arg, "-sourcehome") {
			catalogArgs.SourceHome = parts[1]

		} else if strings.HasPrefix(arg, "-arg") {
			catalogArgs.Args[parts[1]] = parts[2]

			gen.Params[parts[1]] = parts[2]
		} else if strings.HasPrefix(arg, "-define") {
			var designDefine loader.DesignDefine
			designDefine.Form(parts)
			catalogArgs.DesignDefine = &designDefine

		} else if strings.HasPrefix(arg, "-reader") {
			catalogArgs.Reader = export.GetDesignIO(parts[1])

		}
	}
	return &catalogArgs
}
